using System.Collections.Generic;
using System.Data;
using Magiq.Behaviors;
using Magiq.Delete;

namespace Magiq.Databases.Delete
{
    public class DatabaseDeleteBehavior<T> : DefaultBehavior, IDatabaseDeleteBehavior<T> where T : class
    {
        private IDelete<T> delete;
        private IDatabaseAdapter databaseAdapter;

        public void Initialize(IDatabaseAdapter databaseAdapter, IDelete<T> delete)
        {
            this.databaseAdapter = databaseAdapter;
            this.delete = delete;
        }

        public IDbCommand BuildCommand(DatabaseDelete<T> databaseDelete)
        {
            var builder = new DeleteCommandBuilder(databaseDelete.DatabaseAdapter, databaseDelete.Source.Query());
            return builder.GetCommand();
        }

        public IEnumerable<DatabaseDelete<T>> BuildDatabaseDeletes()
        {
            return databaseAdapter.BuildDatabaseDeletes(delete);
        }
    }
}